package model

import (
	"gorm.io/gorm"
	"time"
	"user-srv/basic/config"
)

type User struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	Mobile    string         `gorm:"column:mobile;type:char(11);not null;" json:"mobile"`
	Password  string         `gorm:"column:password;type:char(32);not null;" json:"password"`
	Name      string         `gorm:"column:name;type:varchar(60);not null;" json:"name"`
	Status    int8           `gorm:"column:status;type:tinyint(1);not null;" json:"status"`
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}

func (u *User) CreateUser() error {
	return config.DB.Create(&u).Error
}

func (u *User) GetUser() error {
	return config.DB.Where("mobile = ?", u.Mobile).Find(&u).Error
}

type Comment struct {
	Id        int32          `gorm:"column:id;type:int;primaryKey;not null;" json:"id"`
	VideoId   int32          `gorm:"column:video_id;type:int;not null;" json:"video_id"`
	UserId    int32          `gorm:"column:user_id;type:int;not null;" json:"user_id"`
	Content   string         `gorm:"column:content;type:varchar(300);not null;" json:"conent"`
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (c *Comment) TableName() string {
	return "comment"
}

func (c *Comment) AddComment() error {
	return config.DB.Create(&c).Error
}
